package com.lin.chapter21;

import java.util.List;

public class Client {
	public static void main(String[] args) {
		Branch root = compositeCorpTree();
		System.out.println(getTreeInfo(root));
	}

	public static Branch compositeCorpTree(){
		Branch root = new Branch("王大麦子", "总经理", 100000);

		Branch developDep = new Branch("刘达曲子", "研发部门经理", 10000);
		Branch salesDep = new Branch("马二拐子", "销售部门经理", 20000);
		Branch financeDep = new Branch("赵三坨子", "财务部经理", 30000);

		Branch firstDevGroup = new Branch("杨三也写", "开发一组组长", 5000);
		Branch secondDevGroup = new Branch("吴大棒槌", "开发二组组长", 6000);

		Leaf a = new Leaf("a", "开发人员", 2000);
		Leaf b = new Leaf("b", "开发人员", 2000);
		Leaf c = new Leaf("c", "开发人员", 2000);
		Leaf d = new Leaf("d", "开发人员", 2000);
		Leaf e = new Leaf("e", "开发人员", 2000);
		Leaf f = new Leaf("f", "开发人员", 2000);
		Leaf g = new Leaf("g", "开发人员", 2000);
		Leaf h = new Leaf("h", "销售人员", 2000);
		Leaf i = new Leaf("i", "销售人员", 2000);
		Leaf j = new Leaf("j", "财务人员", 5000);
		Leaf k = new Leaf("k", "CEO 秘书", 8000);

		Leaf zhenglaoLiu = new Leaf("郑老六", "研发部副经理", 20000);

		root.addSubordinate(k);
		root.addSubordinate(developDep);
		root.addSubordinate(salesDep);
		root.addSubordinate(financeDep);

		developDep.addSubordinate(zhenglaoLiu);
		developDep.addSubordinate(firstDevGroup);
		developDep.addSubordinate(secondDevGroup);

		firstDevGroup.addSubordinate(a);
		firstDevGroup.addSubordinate(b);
		firstDevGroup.addSubordinate(c);
		secondDevGroup.addSubordinate(d);
		secondDevGroup.addSubordinate(e);
		secondDevGroup.addSubordinate(f);

		salesDep.addSubordinate(h);
		salesDep.addSubordinate(i);

		financeDep.addSubordinate(j);

		return root;

	}

	public static String getTreeInfo(Branch root){
		List<Corp> subordinate = root.getSubordinate();
		String info = "";
		for (Corp corp : subordinate) {
			info += corp.getInfo() + "\n";
			if (corp instanceof Branch)
				info += "\n" + getTreeInfo((Branch)corp);
		}
		return  info;
	}
}
